<?php
class Cip_samples_m extends MY_Model {
	/**
	 * Insert a new category into the database
	 * @access public
	 * @param array $input The data to insert
	 * @return string
	 */
	public function insert($input = array())
	{
		$this->load->helper('text');
		parent::insert(array(
			'image'=>$input['image'],
			'group_id'=>$input['group_id'],
			'built'=>$input['built']
		));
		return $input['image'];
	}
	/**
	 * Update an existing category
	 * @access public
	 * @param int $id The ID of the category
	 * @param array $input The data to update
	 * @return bool
	 */
	public function update($id, $built)
	{
		return parent::update($id, array(
			'built'	=> $built
		));
	}
	public function getSamples(){
		return $this->cip_samples_m->select('cip_samples.id, cip_samples.image, cip_samples.group_id, g.title, g.url, g.comment')
						//->from('cip_samples s')
						->join('cip_groups g','cip_samples.group_id = g.id')
						->where('g.valid', 1)
						->get_all();
	}
	public function getSamplesByCategory($categoryId){
		return $this->cip_samples_m->select('cip_samples.id, cip_samples.image, cip_samples.group_id, g.title, g.url, g.comment')
						//->from('cip_samples s')
						->join('cip_groups g','cip_samples.group_id = g.id')
						->where('g.category_id', $categoryId)
						->where('g.valid', 1)
						->get_all();
	}
}